<?php
namespace App\Http\Controllers\before;
use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Model\Order;
use App\Model\Goods;
class ProDetController  extends Controller{
    public function index(){
        $id=$_GET['id'];
        $res=DB::select('select * from goods where id="'.$id.'"');

        return view('prodet.index',['res'=>$res]);
    }

    public function order(Request $request){
//                echo 'wqewq';EXIT;
        $data=$request->all();
//        var_dump($data);die();
        $data['order_id'] = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
        //echo $order_id;exit;
        unset($data['_token']);


        $data['order_sum_price']=$data['order_num']*$data['p_price'];
        unset($data['p_price']);
        //print_r($data);exit;
        $res=Order::insert($data);
        if($res){
            echo '预订成功';
//             return redirect('shoppingcontroller/book');
        }
    }

    public function yuding(Request $request){
        $id=$_REQUEST['id'];
        //echo $id;exit;
//        $data=Goods::where('id',$id)->first();

        $data=Goods::where('id',$id)->first()->toArray();


//        print_r($data);exit;
        return view('ProDet/yuding',['list'=>$data]);

    }


}